package com.qingrongby.shop.api.v1;

import com.qingrongby.shop.core.interceptors.ScopeLevel;
import com.qingrongby.shop.exception.http.NotFoundException;
import com.qingrongby.shop.model.Banner;
import com.qingrongby.shop.service.BannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * @CLASSNAME Test
 * @DESCRIPTION TODO
 * @AUTHOR hzp
 * @DATE 2020/6/20
 * @VERSION 1.0
 **/
@RestController
@Api(tags = "banner类型接口")
@RequestMapping("v1/banner")
@Validated
public class BannerController {

    @Autowired
    private BannerService bannerService;

    /**
     *@description 通过id进行获取banner
     *@return {@link null}
     *@author hzp
     *@date  2020/6/21
     */
    @GetMapping("/id/{id}")
    @ApiOperation(value = "banner列表接口")
    @ApiImplicitParam(name = "id",defaultValue ="1")
    @ResponseBody
    public Banner index(@PathVariable(name = "id") Long id) throws NotFoundException {
        Banner banner = bannerService.findById(id);
        if(banner==null){
            throw new NotFoundException(30005);
        }
        return  banner;
    }

    @GetMapping("/name/{name}")
    @ApiOperation(value = "通过名称获取banner")
    @ApiImplicitParam(name = "name",value = "b-1")
    @ResponseBody
    public Banner bannerByName(@PathVariable(name = "name") String name) throws NotFoundException {
        Banner banner=bannerService.findByName(name);
        if(banner==null){
            throw new NotFoundException(30005);
        }
        return banner;
    }

    @GetMapping("/test/scope")
    @ApiOperation(value = "测试scope")
    @ResponseBody
    @ScopeLevel(5)
    public String login(){
        return "";
    }

}
